package com.lb.jwitter.action;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;

import com.opensymphony.xwork2.Action; 
import com.opensymphony.xwork2.ActionContext;
import com.lb.jwitter.service.ConditionReport;
import com.lb.jwitter.service.TblCanBo;
import com.lb.jwitter.service.TblCanBoService;
import com.lb.jwitter.service.TblQLDTTXABienNhanHoSo;
import com.lb.jwitter.service.TblQLDTTXABienNhanHoSoGiayTo;
import com.lb.jwitter.service.TblQLDTTXABienNhanHoSoGiayToService;
import com.lb.jwitter.service.TblQLDTTXABienNhanHoSoService;
import com.lb.jwitter.service.TblQuyenChiTietService;
import com.lb.jwitter.service.TblTaiKhoan;

import com.lb.jwitter.service.TblQLDTTXAHoSoXetTuyen;
import com.lb.jwitter.service.TblQLDTTXAHoSoXetTuyenService;
import com.lb.jwitter.service.TblQLDTTXADMGiayTo;
import com.lb.jwitter.service.TblQLDTTXADMGiayToService;
import com.lb.jwitter.util.ApplicationContextProvider;

 /** 
 * @author QUOCVIET  
 * 
 */ 



@ContextConfiguration(locations="classpath:beans.xml") 
public class TblQLDTTXABienNhanHoSoEditFormAction{
    private int id; 
    public void setId(int id) {
       this.id = id;
 }

    public int getId() {
       return id;
 }

    private int pageSize; 
    public int getPageSize() {
       return pageSize;
 }

    private int page; 
    public int getPage() { return page; }

    private int pages; 
    public int getPages() { return pages; }

    private TblQLDTTXABienNhanHoSo tblQLDTTXABienNhanHoSo; 
    public TblQLDTTXABienNhanHoSo getTblQLDTTXABienNhanHoSo() { 
        return tblQLDTTXABienNhanHoSo; 
    } 
    private List<TblQLDTTXABienNhanHoSo> tblQLDTTXABienNhanHoSos; 
    public List<TblQLDTTXABienNhanHoSo>  getTblQLDTTXABienNhanHoSos() {
         return tblQLDTTXABienNhanHoSos; 
      } 

    private TblQLDTTXABienNhanHoSoService tblQLDTTXABienNhanHoSoService; 

    private List<TblCanBo> tblCanBos; 
    public List<TblCanBo>  getTblCanBos(){ 
              return tblCanBos; 
     } 

    private TblCanBoService tblCanBoService; 

    private List<TblQLDTTXAHoSoXetTuyen> tblQLDTTXAHoSoXetTuyens; 
    public List<TblQLDTTXAHoSoXetTuyen>  getTblQLDTTXAHoSoXetTuyens(){ 
              return tblQLDTTXAHoSoXetTuyens; 
     } 

    private TblQLDTTXAHoSoXetTuyenService tblQLDTTXAHoSoXetTuyenService; 

    private List<TblQLDTTXABienNhanHoSoGiayTo> tblQLDTTXABienNhanHoSoGiayTos; 
    public List<TblQLDTTXABienNhanHoSoGiayTo>  getTblQLDTTXABienNhanHoSoGiayTos(){ 
              return tblQLDTTXABienNhanHoSoGiayTos; 
     } 

    private TblQLDTTXABienNhanHoSoGiayToService tblQLDTTXABienNhanHoSoGiayToService; 

    private List<TblQLDTTXADMGiayTo> tblQLDTTXADMGiayTos; 
    public List<TblQLDTTXADMGiayTo>  getTblQLDTTXADMGiayTos(){ 
              return tblQLDTTXADMGiayTos; 
     } 

    private TblQLDTTXADMGiayToService tblQLDTTXADMGiayToService; 
    private TblQLDTTXAHoSoXetTuyen tblQLDTTXAHoSoXetTuyen;
    private Long tblQLDTTXAHoSoXetTuyenId;
    
    private TblTaiKhoan taiKhoanDangNhap;

	private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; public String execute() throws Exception 
{ 
 try{ 	
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_BienNhanHoSo", "sua")){ 
        return "noprivilege"; 
    } 
	
	
       tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient");
       
       if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_BienNhanHoSo", "sua")){
    	   
    	   return "noprivilege";
       }

        tblQLDTTXABienNhanHoSoService = (TblQLDTTXABienNhanHoSoService) context.getBean("tbl_QLDTTXA_BienNhanHoSoClient"); 

        tblCanBoService = (TblCanBoService) context.getBean("tbl_CanBoClient"); 
  
        tblQLDTTXAHoSoXetTuyenService = (TblQLDTTXAHoSoXetTuyenService) context.getBean("tbl_QLDTTXA_HoSoXetTuyenClient"); 
 
        tblQLDTTXABienNhanHoSoGiayToService = (TblQLDTTXABienNhanHoSoGiayToService) context.getBean("tbl_QLDTTXA_BienNhanHoSo_GiayToClient"); 
 
        tblQLDTTXADMGiayToService = (TblQLDTTXADMGiayToService) context.getBean("tbl_QLDTTXA_DM_GiayToClient"); 

        tblQLDTTXABienNhanHoSo = tblQLDTTXABienNhanHoSoService.gettblQLDTTXABienNhanHoSo(new Long(id)); 
        
//        tblCanBos = tblCanBoService.findAlltblCanBo(0, 0);
//        tblQLDTTXAHoSoXetTuyens = tblQLDTTXAHoSoXetTuyenService.findAlltblQLDTTXAHoSoXetTuyen(0, 0);
        
        tblQLDTTXAHoSoXetTuyen = tblQLDTTXABienNhanHoSo.getHoSoId();
        
        if(tblQLDTTXAHoSoXetTuyen != null )
        	tblQLDTTXAHoSoXetTuyenId = tblQLDTTXAHoSoXetTuyen.getId();
        else 
        	tblQLDTTXAHoSoXetTuyenId = new Long(0);
        
   List<ConditionReport> cons = new ArrayList<ConditionReport>(); 
      tblQLDTTXADMGiayTos =       tblQLDTTXADMGiayToService.findAlltblQLDTTXADMGiayTo(0, 0); 
   if (id != 0) 
   { 
       ConditionReport con = new ConditionReport(); 
       con.setCol("bienNhanId.id"); 
       con.setValue1(new Long(id)); 
       con.setOperator("eq"); 
       cons.add(con); 
   } 
   tblQLDTTXABienNhanHoSoGiayTos = tblQLDTTXABienNhanHoSoGiayToService.findtblQLDTTXABienNhanHoSoGiayToByCondition(cons, pageSize, page); 
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
      System.out.println("Loi EditForm tbl_QLDTTXA_BienNhanHoSo Action"); 
     e.printStackTrace(); 
    return Action.ERROR; 
 } 
 }

	public TblTaiKhoan getTaiKhoanDangNhap() {
		return taiKhoanDangNhap;
	}

	public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) {
		this.taiKhoanDangNhap = taiKhoanDangNhap;
	}

	public TblQLDTTXAHoSoXetTuyen getTblQLDTTXAHoSoXetTuyen() {
		return tblQLDTTXAHoSoXetTuyen;
	}

	public void setTblQLDTTXAHoSoXetTuyen(
			TblQLDTTXAHoSoXetTuyen tblQLDTTXAHoSoXetTuyen) {
		this.tblQLDTTXAHoSoXetTuyen = tblQLDTTXAHoSoXetTuyen;
	}

	public Long getTblQLDTTXAHoSoXetTuyenId() {
		return tblQLDTTXAHoSoXetTuyenId;
	}

	public void setTblQLDTTXAHoSoXetTuyenId(Long tblQLDTTXAHoSoXetTuyenId) {
		this.tblQLDTTXAHoSoXetTuyenId = tblQLDTTXAHoSoXetTuyenId;
	} 
 } 
 
